package com.eascs.web.o2o.scheduler.dao;

import com.eascs.app.dao.JdbcSession;
import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.inject.Inject;
import java.util.List;

@Repository
public class O2oh5Dao {
	@Inject
	JdbcSession jdbcSessionForH5;
	
	public <T> PageResult<T> findDataWithPageByMySql(SqlPageQuery<T> sqlPageQuery) {
		return this.jdbcSessionForH5.findDataWithPage(sqlPageQuery);
	}
	
	
	
	public List<Object[]> findParams(String sql,Object...params ){
		return this.jdbcSessionForH5.findObjectsList(sql, params);
	}

	/**
	 * s 保存该表数据
	 */
	@Transactional(transactionManager = "transactionManagerDbForH5")
	public boolean saveEntity(Object entity) {
		return jdbcSessionForH5.insert(entity)>0;
	}
	
	
	@Transactional(transactionManager = "transactionManagerDbForH5")
	public boolean updateEntity(Object entity) {
		return jdbcSessionForH5.updateById(entity)>0;
	}

	/**
	 * 删除数据
	 */
	public boolean deleteEntity(String delSql) {
		return jdbcSessionForH5.execute(delSql)>0;
	}

	/**
	 * @param sql
	 *            保存
	 */
    @Transactional(transactionManager = "transactionManagerDbForH5")
	public boolean excuteSql(String sql, Object... params) {
		return jdbcSessionForH5.execute(sql, params)>0;

	}
    
    /**
	 * 实体集合
	 */
	public List<Object[]> findObjectsList(String sql){
		return jdbcSessionForH5.findObjectsList(sql);
	}
	
    public <T> List<T> findSimpleObjectList(String sql, Class<T> requiredType, Object... params){
		return jdbcSessionForH5.findSimpleObjectList(sql, requiredType, params);
	}
    
	
    public Integer countMysql(String sql,Object... params) {
		return this.jdbcSessionForH5.findInteger(sql, params);

	}
    
  
    
    

    public <T> Object findEntityForMysql(String sql, Class<T> requiredType, Object... params){
    	return jdbcSessionForH5.findEntity(sql, requiredType, params);
    }
    
    public<T> List<T>  findEntitysForMysql(String sql, Class<T> requiredType, Object... params){
    	return jdbcSessionForH5.findEntitys(sql, requiredType, params);
    }
    

	
}
